Toast = require('antd-mobile/lib/toast')
#登陆成功或失败后，需要更新缓存中登陆信息
{AsyncStorage} = require('react-native')
userInfo = (state={},action)->
  switch action.type
    when 'USER_INFO/LOGIN_START'
      Object.assign {},{token:null,pilotCode:null,pilotName:null}
      state
    when 'USER_INFO/LOGIN_COMPLETED'
      # str = JSON.stringify action.payload
      # AsyncStorage.setItem 'userInfo',str
      Object.assign {},state,action.payload
    when 'USER_INFO/LOGIN_FAIL'
      # AsyncStorage.removeItem 'userInfo',->
      #   Toast.fail(action.payload.message)
      Object.assign {},{token:null,pilotCode:'guest',pilotName:'游客'}
    when 'USER_INFO/LOGOUT'
      # AsyncStorage.removeItem 'userInfo'
      Object.assign {},{token:null,pilotCode:'guest',pilotName:'游客'}
    when 'USER_INFO/CHANGE_PASS_START'
      state
    when 'USER_INFO/CHANGE_PASS_COMPLETED'
      Object.assign {},{token:null,pilotCode:'guest',pilotName:'游客'}
    when 'USER_INFO/CHANGE_PASS_FAIL'
      Object.assign {},{token:null,pilotCode:'guest',pilotName:'游客'}
      state
    else
      state

module.exports = userInfo
